package 力扣_算法题综合.高频面试算法;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author zx
 * @create 2023-02-24 10:52
 */
public class 用队列实现栈_225 {
    /**
     * 在这里，queue2只是起辅助作用
     */
    class MyStack {
        Deque<Integer> queue1;//主栈
        Deque<Integer> queue2;//辅助栈

        public MyStack() {
            queue1 = new ArrayDeque<>();
            queue2 = new ArrayDeque<>();
        }

        public void push(int x) {
            while (!queue1.isEmpty()) {
                queue2.offer(queue1.poll());
            }
            queue1.offer(x);
            while (!queue2.isEmpty()) {
                queue1.offer(queue2.poll());
            }
        }

        public int pop() {
            return queue1.poll();
        }

        public int top() {
            return queue1.peek();
        }

        public boolean empty() {
            return queue1.isEmpty();
        }
    }
}
